﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:ddue="http://ddue.schemas.microsoft.com/authoring/2003/5" 
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:tool="http://www.microsoft.com/tooltip"
XMLNS:[default]="http://ddue.schemas.microsoft.com/authoring/2003/5">
<head>
    <title>Message Sample Using WCF Services</title>
    <meta content="text/html; CHARSET=utf-8" http-equiv="Content-Type" />
    <meta name="saave" content="history" />
    <link rel="stylesheet" type="text/css" href="../../../../CommonFiles/Classic.css" />
</head>
<body>
<table cellspacing="0" cellpadding="0" width="99%">
<tbody>
<tr>
<td>
    <div id="header">
        <table id="topTable" width="100%">
            <tbody>
                <tr id="headerTableRow1">
                    <td align="left">
                        <span id="runningHeaderText"></span>
                    </td>
                </tr>
                <tr id="headerTableRow2">
                    <td align="left">
                        <span id="nsrTitle">Message Sample Using WCF Services</span>
                    </td>
                </tr>
                <tr id="headerTableRow3">
                    <td align="left"></td>
                </tr>
            </tbody>
        </table>
    </div>
    <div id="mainSection">
        <div id="mainBody">
            <p>This sample demonstrates how to use the Windows Azure Service Bus using the WCF service model.</p>
            <p>The sample shows the use of the WCF service model to perform non-session communication via a Service Bus queue. The sample demonstrates this using a Ping service scenario. In this scenario, different senders send messages to the Ping service. All the messages are processed by the service. The service creates only one instance and processes all the messages in the same instance.</p>
            <p style="text-align:center"><img src="ServiceDiagram.jpg" alt="OrderService" /></p>
            <p>The sample prompts for service namespace credentials for the purpose of creating and deleting the queues. The credentials are used to authenticate with the Access Control 
                service, and acquire an access token that proves to the Service Bus infrastructure that the client is authorized to create or delete the queue. The sender and service use the credentials defined in the config file. </p>
            <h2 class="heading">Prerequisites</h2>
            <div id="sectionSection0" class="section">
                <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">
                    <p>If you haven't already done so, please read the release notes document that explains how to sign up for a Windows Azure account and how to configure your environment. </p>
                </content>
            </div>
            <h2 class="heading">Configuring the Sample</h2>
            <div id="sectionSection1" class="section">
                <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">
                    <p>When the solution is opened in Visual Studio, update the &lt;behaviors&gt; and &lt;client&gt; sections in the App.config file of the PingClient project. Also, update the &lt;behaviors&gt; and &lt;services&gt; sections in the App.config file of the PingService project.</p>
                    <p>The value for ‘issuerSecret’ should be available upon signup for a Windows Azure account and upon configuring your environment. Please read the release notes for details.</p>
                    <p>The value for ‘address’ in the &lt;client&gt; and &lt;services&gt; sections is a Service Bus Uri that points to the queue entity. The Uri should be of type <b>sb://&lt;ServiceBus Namespace&gt;.servicebus.windows.net/PingQueue</b> where the <b>‘PingQueue’</b> is the entity name. Note that the Uri scheme ‘sb’ is mandatory for all runtime operations such as send/receive.</p>
                    <div class="code" xmlns="">
                        <span codeLanguage="CSharp">
                            <table cellspacing="0" cellpadding="0" width="100%">
                                <tbody>
                                    <tr>
                                        <th>PingClient App.Config</th>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <pre>
                                                    &lt;behaviors&gt;
                                                      &lt;endpointBehaviors&gt;
                                                        &lt;behavior name="securityBehavior"&gt;
                                                          &lt;transportClientEndpointBehavior&gt;
                                                            &lt;tokenProvider&gt;
                                                              &lt;sharedSecret issuerName="owner" issuerSecret="[Issuer key]" /&gt;
                                                            &lt;/tokenProvider&gt;
                                                          &lt;/transportClientEndpointBehavior&gt;
                                                        &lt;/behavior&gt;
                                                      &lt;/endpointBehaviors&gt;
                                                    &lt;/behaviors&gt;
                                                    
                                                  &lt;client&gt;
                                                    &lt;endpoint name="pingClient"
                                                              address="sb://[ServiceBus Namespace].servicebus.windows.net/PingQueue"
                                                              binding="netMessagingBinding" bindingConfiguration="messagingBinding"
                                                              contract="Microsoft.Samples.SessionMessages.IPingServiceContract"
                                                              behaviorConfiguration="securityBehavior"/&gt;
                                                  &lt;/client&gt;</pre>
                                        </td>
                                    </tr>
                                    <tr>
                                        <th>PingService App.Config </th>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <pre>
                                                    &lt;behaviors&gt;
                                                      &lt;endpointBehaviors&gt;
                                                        &lt;behavior name="securityBehavior"&gt;
                                                          &lt;transportClientEndpointBehavior&gt;
                                                            &lt;tokenProvider&gt;
                                                              &lt;sharedSecret issuerName="owner" issuerSecret="[Issuer key]" /&gt;
                                                            &lt;/tokenProvider&gt;
                                                          &lt;/transportClientEndpointBehavior&gt;
                                                        &lt;/behavior&gt;
                                                      &lt;/endpointBehaviors&gt;
                                                    &lt;/behaviors&gt;

                                                    &lt;services&gt;
                                                      &lt;service name="Microsoft.Samples.SessionMessages.PingService"&gt;
                                                        &lt;endpoint name="pingServiceEndPoint" 
                                                                  address="sb://[ServiceBus Namespace].servicebus.windows.net/PingQueue"
                                                                  binding="netMessagingBinding" bindingConfiguration="messagingBinding"
                                                                  contract="Microsoft.Samples.SessionMessages.IPingServiceContract"
                                                                  behaviorConfiguration="securityBehavior" /&gt;
                                                      &lt;/service&gt;
                                                    &lt;/services&gt;</pre>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </span>
                    </div>
                </content>
            </div>
            <h2 class="heading">Configuration File</h2>
            <div id="sectionSection3" class="section">
                <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">
                    <p>The sender and receiver use NetMessagingBinding, which is defined in the respective App.config files. NetMessagingBinding uses BinaryMessageEncoding as its encoder and NetMessagingTransportBindingElement as its transport. The TransportSettings property of the transport binding element represents the runtime factory used by Service Bus. An extension section is required be added to the config file in order to use Service Bus components with WCF.</p>
                    <p>In addition to the binding, both the config files have a &lt;behaviors&gt; section, which defines TransportClientEndpointBehavior. Service Bus credentials are passed on to the client and service via this endpoint behavior. </p>
                    <div class="code" xmlns="">
                        <span codeLanguage="CSharp">
                            <table cellspacing="0" cellpadding="0" width="100%">
                                <tbody>
                                    <tr>
                                        <th>App.Config - Config Extensions and Binding</th>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <pre>
                                                &lt;extensions&gt;
                                                  &lt;bindingElementExtensions&gt;
                                                    &lt;add name="netMessagingTransport" type="Microsoft.ServiceBus.Messaging.Configuration.NetMessagingTransportExtensionElement, 
                                                                   Microsoft.ServiceBus, Version=1.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /&gt;
                                                  &lt;/bindingElementExtensions&gt;
                                                  &lt;bindingExtensions&gt;
                                                    &lt;add name="netMessagingBinding" type="Microsoft.ServiceBus.Messaging.Configuration.NetMessagingBindingCollectionElement, 
                                                                   Microsoft.ServiceBus, Version=1.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /&gt;
                                                  &lt;/bindingExtensions&gt;
                                                &lt;/extensions&gt;
                                                &lt;behaviors&gt;
                                                  &lt;endpointBehaviors&gt;
                                                    &lt;behavior name="securityBehavior"&gt;
                                                      &lt;transportClientEndpointBehavior&gt;
                                                        &lt;tokenProvider&gt;
                                                          &lt;sharedSecret issuerName="owner" issuerSecret="[Issuer key]" /&gt;
                                                        &lt;/tokenProvider&gt;
                                                      &lt;/transportClientEndpointBehavior&gt;
                                                    &lt;/behavior&gt;
                                                  &lt;/endpointBehaviors&gt;
                                                &lt;/behaviors&gt;
                                                &lt;bindings&gt;
                                                  &lt;netMessagingBinding&gt;
                                                    &lt;binding name="messagingBinding" closeTimeout="00:03:00" openTimeout="00:03:00" receiveTimeout="00:03:00" sendTimeout="00:03:00" sessionIdleTimeout="00:01:00" prefetchCount="-1"&gt;
                                                      &lt;transportSettings batchFlushInterval="00:00:01"/&gt;
                                                    &lt;/binding&gt;
                                                  &lt;/netMessagingBinding&gt;
                                                &lt;/bindings&gt;</pre>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </span>
                    </div>
                    <p>In the configuration files, NetMessagingBinding has properties for SessionIdleTimeOut, PrefetchCount, and BatchFlushInterval. SessionIdleTimeOut property allows the ServiceHost dispatcher to close an instance of the service if it is idle for more than the specified time interval. The default value for SessionIdleTimeout is 1 minute. BatchFlushInterval is responsible for implicitly batching send operations or complete operations. The Service Bus implicitly batches the send operation from sender or complete operation from receiver for the specified time to avoid multiple round-trips. The default value of BatchFlushInterval is 20 milliseconds. </p>
                    <p>The Pingclient configuration file defines the client object and the PingService configuration file defines the service object.</p>
                    <div class="code" xmlns="">
                        <span codeLanguage="CSharp">
                            <table cellspacing="0" cellpadding="0" width="100%">
                                <tbody>
                                    <tr>
                                        <th>App.Config - Client and Service Definition</th>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <pre>
                                                  &lt;client&gt;
                                                    &lt;endpoint name="pingClient"
                                                              address="[Enter Endpoint address]"
                                                              binding="netMessagingBinding" bindingConfiguration="messagingBinding"
                                                              contract="Microsoft.Samples.SessionMessages.IPingServiceContract"
                                                              behaviorConfiguration="securityBehavior"/&gt;
                                                  &lt;/client&gt;
                                                  
                                                    &lt;services&gt;
                                                      &lt;service name="Microsoft.Samples.SessionMessages.PingService"&gt;
                                                        &lt;endpoint name="pingServiceEndPoint" 
                                                                  address="[Enter Endpoint address]"
                                                                  binding="netMessagingBinding" bindingConfiguration="messagingBinding"
                                                                  contract="Microsoft.Samples.SessionMessages.IPingServiceContract"
                                                                  behaviorConfiguration="securityBehavior" /&gt;
                                                      &lt;/service&gt;
                                                    &lt;/services&gt;</pre>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </span>
                    </div>
                </content>
            </div>
            <h2 class="heading">Credentials</h2>
            <div id="sectionSection4" class="section">
                <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">
                    <p>The sample obtains the user credentials and creates a Service Bus NamespaceManager object. This entity holds the credentials and is used for messaging management operations - in this case, to create and delete queues.</p>
                    <div class="code" xmlns="">
                        <span codeLanguage="CSharp">
                            <table cellspacing="0" cellpadding="0" width="100%">
                                <tbody>
                                    <tr>
                                        <th>C#</th>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <pre>
                                                public static void GetUserCredentials()
                                                {
                                                    // User namespace
                                                    Console.WriteLine("Please provide the namespace to use:");
                                                    serviceBusNamespace = Console.ReadLine();

                                                    // Issuer name
                                                    Console.WriteLine("Please provide the Issuer name to use:");
                                                    serviceBusIssuerName = Console.ReadLine();

                                                    // Issuer key
                                                    Console.WriteLine("Please provide the Issuer key to use:");
                                                    serviceBusIssuerKey = Console.ReadLine();
                                                }

                                                // Create the NamespaceManager for management operations (queue)
                                                static void CreateNamespaceManager()
                                                {
                                                    // Create TokenProvider for access control service
                                                    TokenProvider credentials = TokenProvider.CreateSharedSecretTokenProvider(ServiceBusIssuerName, ServiceBusIssuerKey);

                                                    // Create the management Uri
                                                    Uri managementUri = ServiceBusEnvironment.CreateServiceUri("sb", ServiceBusNamespace, string.Empty);
                                                    namespaceClient = new NamespaceManager(managementUri, credentials);
                                                }

                                                // Create the entity (queue)
                                                static QueueDescription CreateQueue(bool session)
                                                {
                                                    QueueDescription queueDescription = new QueueDescription(PingQueueName) { RequiresSession = session };

                                                    // Try deleting the queue before creation. Ignore exception if queue does not exist.
                                                    try
                                                    {
                                                        namespaceClient.DeleteQueue(queueDescription.Path);
                                                    }
                                                    catch (MessagingEntityNotFoundException)
                                                    {
                                                    }

                                                    return namespaceClient.CreateQueue(queueDescription);
                                                }                                            
                                            </pre>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </span>
                    </div>
                    <p>The preceding code prompts for the issuer credential and then constructs the listening URI using that information. The static ServiceBusEnvironment.CreateServiceUri function is provided to help construct the URI with the correct format and domain name. It is strongly recommended that you use this function instead of building the URI from scratch because the URI construction logic and format might change in future releases. At present, the resulting URI is scheme://&lt;service-namespace&gt;.servicebus.windows.net/. </p>
                    <p>The CreateNamespaceManager() function creates the object to perform management operations, in this case to create and delete queues. Both ‘https’ and ‘sb’ Uri schemes are allowed as a part of service Uri.</p>
                    <p>The CreateQueue(bool session) function creates a queue with the RequireSession property set as per the argument passed.</p>
                </content>
            </div>
            <h2 class="heading">Data Contract</h2>
            <div id="sectionSection5" class="section">
                <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">
                    <p>The sample uses an PingData data contract to communicate between client and service. This data contract has 
                        two data members of type string.</p>
                    <div class="code" xmlns="">
                        <span codeLanguage="CSharp">
                            <table cellspacing="0" cellpadding="0" width="100%">
                                <tbody>
                                    <tr>
                                        <th>C#</th>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <pre>
                                                [DataContract(Name="PingDataContract", Namespace="Microsoft.Samples.SessionMessages")]
                                                public class PingData
                                                {
                                                    [DataMember]
                                                    public string Message;

                                                    [DataMember]
                                                    public string SenderId;

                                                    public PingData()
                                                        : this(string.Empty, string.Empty)
                                                    {
                                                    }

                                                    public PingData(string message, string senderId)
                                                    {
                                                        this.Message = message;
                                                        this.SenderId = senderId;
                                                    }
                                                }</pre>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </span>
                    </div>
                </content>
            </div>
            <h2 class="heading">Sender</h2>
            <div id="sectionSection6" class="section">
                <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">
                    <p>Service Bus supports IOutputChannel for sending messages using NetMessagingBinding. In the sample, the clients create a random message using the RandomString() function and then send the message to the service. The 
                        PingClient is defined in its app.config file.</p>
                    <div class="code" xmlns="">
                        <span codeLanguage="CSharp">
                            <table cellspacing="0" cellpadding="0" width="100%">
                                <tbody>
                                    <tr>
                                        <th>C#</th>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <pre>
                                                static void Main(string[] args)
                                                {
                                                    ParseArgs(args);

                                                    // Send messages to queue which does not require session
                                                    Console.Title = "Ping Client";

                                                    // Create sender to Order Service
                                                    ChannelFactory&lt;IPingServiceContract&gt; factory = new ChannelFactory&lt;IPingServiceContract&gt;(SampleManager.PingClientConfigName);
                                                    IPingServiceContract clientChannel = factory.CreateChannel();
                                                    ((IChannel)clientChannel).Open();

                                                    // Send messages
                                                    numberOfMessages = random.Next(10, 30);
                                                    Console.WriteLine("[Client{0}] Sending {1} messages to {2}...", senderId, numberOfMessages, SampleManager.PingQueueName);
                                                    SendMessages(clientChannel);

                                                    // Close sender
                                                    ((IChannel)clientChannel).Close();
                                                    factory.Close();

                                                    Console.WriteLine("\nSender complete.");
                                                    Console.WriteLine("\nPress [Enter] to exit.");
                                                    Console.ReadLine();
                                                }

                                                static void SendMessages(IPingServiceContract clientChannel)
                                                {
                                                    // Send messages to queue which requires session:
                                                    for (int i = 0; i &lt; numberOfMessages; i++)
                                                    {
                                                        // Send message 
                                                        PingData message = CreatePingData();
                                                        clientChannel.Ping(message);
                                                        SampleManager.OutputMessageInfo("Send", message);
                                                        Thread.Sleep(200);
                                                    }
                                                }

                                                static PingData CreatePingData()
                                                {
                                                    // Generating a random message
                                                    return new PingData(RandomString(), senderId);
                                                }

                                                // Creates a random string
                                                static string RandomString()
                                                {
                                                    StringBuilder builder = new StringBuilder();
                                                    int size = random.Next(5, 15);
                                                    char ch;
                                                    for (int i = 0; i &lt; size; i++)
                                                    {
                                                        ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
                                                        builder.Append(ch);
                                                    }

                                                    return builder.ToString();
                                                }</pre>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </span>
                    </div>
                </content>
            </div>
            <h2 class="heading">Service</h2>
            <div id="sectionSection6" class="section">
                <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">
                    <p>The sample illustrates a Ping service as described above. The Ping service implements IPingServiceContract service contract. The operation attribute ReceiveContextEnabled is set with manual control set to true. This requires an explicit ReceiveContext.Complete operation to be performed for every message received. The service has behavior InstanceContextMode set to single. The service will only create one instance to process all available messages in the queue. </p>
                    <p>Note that NetMessagingBinding only supports one-way communication. Therefore, OperationContract must explicitly set the attribute IsOneWay to true. The service is defined in its App.config file.</p>
                    <div class="code" xmlns="">
                        <span codeLanguage="CSharp">
                            <table cellspacing="0" cellpadding="0" width="100%">
                                <tbody>
                                    <tr>
                                        <th>C#</th>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <pre>
                                                [ServiceContract]
                                                public interface IPingServiceContract
                                                {
                                                    [OperationContract(IsOneWay = true)]
                                                    [ReceiveContextEnabled(ManualControl = true)]
                                                    void Ping(PingData pingData);
                                                }

                                                [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode=ConcurrencyMode.Single)]
                                                public class PingService : IPingServiceContract
                                                {
                                                    [OperationBehavior]
                                                    public void Ping(PingData pingData)
                                                    {
                                                        // Get the message properties
                                                        var incomingProperties = OperationContext.Current.IncomingMessageProperties;
                                                        BrokeredMessageProperty property = (BrokeredMessageProperty)incomingProperties[BrokeredMessageProperty.Name];

                                                        // Print message
                                                        SampleManager.OutputMessageInfo("Receive", pingData);

                                                         //Complete the Message
                                                        ReceiveContext receiveContext;
                                                        if (ReceiveContext.TryGet(incomingProperties, out receiveContext))
                                                        {
                                                            receiveContext.Complete(TimeSpan.FromSeconds(10.0d));
                                                        }
                                                        else
                                                        {
                                                            throw new InvalidOperationException("Receiver is in peek lock mode but receive context is not available!");
                                                        }
                                                    }
                                                }</pre>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </span>
                    </div>
                    <p>The service application subscribes to the faulted event. This will notify the service if any fault occurred during execution and can be handled properly. In the sample, the service is aborted on fault.</p>
                    <div class="code" xmlns="">
                        <span codeLanguage="CSharp">
                            <table cellspacing="0" cellpadding="0" width="100%">
                                <tbody>
                                    <tr>
                                        <th>C#</th>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <pre>
                                                static void Main(string[] args)
                                                {
                                                    Console.Title = "Ping Service";
                                                    Console.WriteLine("Ready to receive messages from {0}...", SampleManager.PingQueueName);

                                                    // Creating the service host object as defined in config
                                                    ServiceHost serviceHost = new ServiceHost(typeof(PingService));

                                                    // Add ErrorServiceBehavior for handling errors encounter by servicehost during execution.
                                                    serviceHost.Description.Behaviors.Add(new ErrorServiceBehavior());

                                                    // Subscribe to the faulted event.
                                                    serviceHost.Faulted += new EventHandler(serviceHost_Faulted);

                                                    // Start service
                                                    serviceHost.Open();

                                                    Console.WriteLine("\nPress [Enter] to Close the ServiceHost.");
                                                    Console.ReadLine();

                                                    // Close the service
                                                    serviceHost.Close();
                                                }

                                                static void serviceHost_Faulted(object sender, EventArgs e)
                                                {
                                                    Console.WriteLine("Fault occured. Aborting the service host object ...");
                                                    ((ServiceHost)sender).Abort();
                                                }                                            
                                            </pre>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </span>
                    </div>
                    <p>The service also implements an ErrorServiceBehavior for unhandled exceptions during service execution. ErrorServiceBehavior is a service behavior which adds an IErrorHandler object to the dispatcher. This object simply prints out all the exceptions except CommunicationException.</p>
                    <div class="code" xmlns="">
                        <span codeLanguage="CSharp">
                            <table cellspacing="0" cellpadding="0" width="100%">
                                <tbody>
                                    <tr>
                                        <th>C#</th>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <pre>
                                                public class ErrorHandler: IErrorHandler
                                                {
                                                    public bool HandleError(Exception error)
                                                    {
                                                        if (!error.GetType().Equals(typeof(CommunicationException)))
                                                        {
                                                            // Handle the exception as required by the application
                                                            Console.WriteLine("Service encountered an exception.");
                                                            Console.WriteLine(error.ToString());
                                                        }

                                                        return true;
                                                    }

                                                    public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
                                                    {
                                                    }
                                                }

                                                public class ErrorServiceBehavior : IServiceBehavior
                                                {
                                                    public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, 
                                                        Collection&lt;ServiceEndpoint&gt; endpoints, BindingParameterCollection bindingParameters)
                                                    {
                                                    }

                                                    public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
                                                    {
                                                        foreach (ChannelDispatcher dispatcher in serviceHostBase.ChannelDispatchers)
                                                        {
                                                            dispatcher.ErrorHandlers.Add(new ErrorHandler());
                                                        }
                                                    }

                                                    public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
                                                    {
                                                    }
                                                }</pre>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </span>
                    </div>
                </content>
            </div>
            <h2 class="heading">Running the Sample</h2>
            <div id="Div2" class="section">
                <content xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">
                    <p>To run the sample, build the solution in Visual Studio or from the command line, then run the executable ‘SampleManager.exe’. The program prompts for your service namespace and the issuer credentials. For the issuer secret, be sure to use the Default Issuer Key value (typically "owner") from the portal, rather than one of the management keys. </p>
                    <p><b>Expected Output - Sample Manager</b></p>
                    <div class="code" xmlns="">
                        <table cellspacing="0" cellpadding="0" width="100%">
                            <tbody>
                                <tr>
                                    <td colspan="2">
                                        <pre class="style2">
                                             Please provide the namespace to use: &lt;Service Namespace&gt;
                                             Please provide the Issuer name to use: &lt;Issuer Name&gt;
                                             Please provide the Issuer key to use: &lt;Issuer Key&gt;
                                             Creating Queues...
                                             Created PingQueue, Queue.RequiresSession = False                                        

                                             Launching senders and receivers...                                         

                                             Press [Enter] to exit.</pre>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    <p><b>Expected Output – Ping Client</b></p>
                    <div class="code" xmlns="">
                        <table cellspacing="0" cellpadding="0" width="100%">
                            <tbody>
                                <tr>
                                    <td colspan="2">
                                        <pre class="style2">
                                            Sending 13 messages to PingQueue...
                                            Send: Message [FHZRADKBZWL] - Group 0.
                                            Send: Message [AMBALBZMY] - Group 0.
                                            Send: Message [OTAKPRFHOSHRH] - Group 0.
                                            Send: Message [IZBDPXUAXXJN] - Group 0.
                                            Send: Message [EMDFSRISFRP] - Group 0.
                                            Send: Message [TWRHTEIFGR] - Group 0.
                                            Send: Message [AVXBCOVCA] - Group 0.
                                            Send: Message [ZAVKM] - Group 0.
                                            Send: Message [AYBDHLPVAC] - Group 0.
                                            Send: Message [ETAHLNADJVPF] - Group 0.
                                            Send: Message [KPOMTW] - Group 0.
                                            Send: Message [XGPIHFNEOGBAA] - Group 0.
                                            Send: Message [QJAUOMUHDTLTX] - Group 0. 

                                            Sender complete. 

                                            Press [Enter] to exit.</pre>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    <p><b>Expected Output - Ping Service</b></p>
                    <div class="code" xmlns="">
                        <table cellspacing="0" cellpadding="0" width="100%">
                            <tbody>
                                <tr>
                                    <td colspan="2">
                                        <pre class="style2">
                                            Ready to receive messages from PingQueue...

                                            Press [Enter] to exit.
                                            Receive: Message[FHZRADKBZWL]
                                            Receive: Message[AMBALBZMY]
                                            Receive: Message[OTAKPRFHOSHRH]
                                            Receive: Message[IZBDPXUAXXJN]
                                            Receive: Message[EMDFSRISFRP]
                                            Receive: Message[TWRHTEIFGR]
                                            Receive: Message[AVXBCOVCA]
                                            Receive: Message[ZAVKM]
                                            Receive: Message[AYBDHLPVAC]
                                            Receive: Message[ETAHLNADJVPF]
                                            Receive: Message[KPOMTW]
                                            Receive: Message[XGPIHFNEOGBAA]
                                            Receive: Message[QJAUOMUHDTLTX]</pre>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>                                                            
                </content>
            </div>
        </div>
        <P xmlns="">
        <hr />
        Did you find this information useful?
            <a href="http://go.microsoft.com/fwlink/?LinkID=155664">
              Please send your suggestions and comments about the documentation.
            </a>
        </P>
    </div>
</td>
</tr>
</tbody>
</table>
</body>
</html>